package kr.hkit.powerjava.chapter14.work;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JButton;

import java.awt.FlowLayout;

import javax.swing.JTextField;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class Programming02 extends JFrame implements ActionListener {
	private JPanel contentPane;
	private JButton btnNewButton;
	private JTextField textField;
	private Programming02_panel panel;
	private JPanel panel_1;
	private Programming02_panel panel_2;
	private JPanel panel_3;
	private Programming02_panel panel_4;
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Programming02 frame = new Programming02();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}
	public String getTextField() {
		return textField.getText();
	}

	public void setTextField(String text) {
		textField.setText(text);
	}
	public Programming02() {
		initialize();
	}
	private void initialize() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 278, 214);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
		setTitle("이자 계산기");
		
		panel_3 = new JPanel();
		contentPane.add(panel_3);
		
		panel_4 = new Programming02_panel("원금을 입력하시오");//원금
		panel_3.add(panel_4);
		
		panel_1 = new JPanel();
		contentPane.add(panel_1);
		
		panel_2 = new Programming02_panel("이율을 입력하시오");//이율
		panel_1.add(panel_2);
		
		
		
		btnNewButton = new JButton("변환");
		btnNewButton.addActionListener(this);
		contentPane.add(btnNewButton);
		
		textField = new JTextField();
		contentPane.add(textField);
		textField.setColumns(20);
	}

	public void actionPerformed(ActionEvent e) {
		int prin=0;
		double rate=0;
		if(e.getActionCommand().equals("변환")){
			try {
				prin=Integer.parseInt(panel_4.getTfpricnipal().trim());
			} catch (NumberFormatException e1) {
				JOptionPane.showMessageDialog(this, "숫자를 입력하세요");
				panel_4.setTfpricnipal("");
			}
			try {
				rate=Double.parseDouble(panel_2.getTfpricnipal().trim());
			} catch (NumberFormatException e1) {
				JOptionPane.showMessageDialog(this, "숫자를 입력하세요");
				panel_4.setTfpricnipal("");
			}textField.setText("이자는"+(Math.round(prin*rate)*10+"원 입니다"));
		}
	}

	
}
